]>
Commit | Line | Data |
---|---|---|
be897af3 RBR |
1 | // Copyright (C) 2024 Rubén Beltrán del Río |
2 | ||
3 | // This program is free software: you can redistribute it and/or modify | |
4 | // it under the terms of the GNU General Public License as published by | |
5 | // the Free Software Foundation, either version 3 of the License, or | |
6 | // (at your option) any later version. | |
7 | ||
8 | // This program is distributed in the hope that it will be useful, | |
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | // GNU General Public License for more details. | |
12 | ||
13 | // You should have received a copy of the GNU General Public License | |
14 | // along with this program. If not, see https://map.tranquil.systems. | |
5e8ff485 RBR |
15 | import SwiftUI |
16 | ||
17 | struct MapBlockers: View { | |
18 | ||
5e8ff485 RBR |
19 | let mapSize: CGSize |
20 | let vertexSize: CGSize | |
21 | let blockers: [Blocker] | |
22 | ||
5e8ff485 RBR |
23 | let cornerSize = CGSize(width: 2.0, height: 2.0) |
24 | ||
25 | var body: some View { | |
26 | ForEach(blockers, id: \.id) { vertex in | |
27 | Path { path in | |
28 | path.addRoundedRect( | |
29 | in: CGRect( | |
30 | origin: CGPoint( | |
31 | x: w(vertex.position.x) + 3 * vertexSize.width, | |
32 | y: h(vertex.position.y) - vertexSize.height * 2 / 3), | |
33 | size: CGSize(width: vertexSize.width / 2, height: vertexSize.height * 2) | |
34 | ), cornerSize: cornerSize) | |
be897af3 | 35 | }.fill(Color.Map.blockerColor) |
5e8ff485 RBR |
36 | } |
37 | } | |
38 | ||
39 | func h(_ dimension: CGFloat) -> CGFloat { | |
40 | max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0)) | |
41 | } | |
42 | ||
43 | func w(_ dimension: CGFloat) -> CGFloat { | |
44 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
45 | } | |
46 | } | |
47 | ||
e2c37ac1 RBR |
48 | #Preview { |
49 | MapBlockers( | |
50 | mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0), | |
51 | blockers: [ | |
52 | Blocker(id: 0, position: CGPoint(x: 50.0, y: 50.0)), | |
53 | Blocker(id: 1, position: CGPoint(x: 10.0, y: 20.0)), | |
54 | ]) | |
5e8ff485 | 55 | } |